
from selenium.webdriver.common.by import By
from pages.trunk import Trunk


class HomePage(Trunk):
    ''''''
    """banner"""
    top_ele = (By.CSS_SELECTOR, ".top")
    """HomePage Menu"""
    home_bridesmaids_ele = (By.CSS_SELECTOR, "#categories-item-0 a")
    home_bridal_ele = (By.CSS_SELECTOR, "#categories-item-1 a")
    home_moms_celebrations_ele = (By.CSS_SELECTOR, "#categories-item-2 a")
    home_party_dresses_ele = (By.CSS_SELECTOR, "#categories-item-3 a")
    home_junior_bridesmaids_ele = (By.CSS_SELECTOR, "#categories-item-4 a")
    home_veils_accessories_ele = (By.CSS_SELECTOR, "#categories-item-5 a")
    home_groomsmen_ele = (By.CSS_SELECTOR, "#categories-item-6 a")
    home_at_home_try_on_dresses_ele = (By.CSS_SELECTOR, "#categories-item-7 a")

    most_popular_title_ele = (By.CSS_SELECTOR, "#most-popular .title")
    shopping_experience_title_ele = (By.CSS_SELECTOR, "#shopping-experience .title")
    shop_our_instagram_title_ele = (By.CSS_SELECTOR, ".index-style-gallery .title")
    view_all_btn_ele = (By.CSS_SELECTOR, "#browse-the-gallery")
    first_instagram_item_ele = (By.CSS_SELECTOR, ".fs-wrapper :first-child.fs-entry-container")

    """其它页面元素，用于校验"""
    seo_cat_name_ele = (By.CSS_SELECTOR, ".seo_cat_name")
    how_it_works_banner_ele = (By.CSS_SELECTOR, ".how_it_works .title")
    style_gallery_page_ele = (By.CSS_SELECTOR, "#style-gallery-page")
    fs_detail_container_ele = (By.CSS_SELECTOR, ".fs-detail-container")

    @property
    def most_popular_title(self):
        """获取Most Popular文本"""
        return self.get_element_text(self.most_popular_title_ele, desc="获取Most Popular文本").strip()

    @property
    def shop_our_instagram_title(self):
        """获取SHOP OUR INSTAGRAM文本"""
        return self.get_element_text(self.shop_our_instagram_title_ele, desc="获取SHOP OUR INSTAGRAM文本").strip()

    @property
    def shopping_experience_title(self):
        """获取re-inventing the bridal shopping experience文本"""
        return self.get_element_text(self.shopping_experience_title_ele, desc="获取shopping_experience文本").strip()

    def __wait_content_visible(self):
        """等待页面图片可见"""
        self.wait_element_to_be_visible(self.top_ele, desc="等待Banner图片可见")

    def verify_home_bridesmaids_jump(self):
        """校验首页bridesmaids的跳转（非导航栏）"""
        self.__wait_content_visible()
        self.click_button(self.home_bridesmaids_ele, desc="点击首页bridesmaids按钮")
        self.wait_element_to_be_visible(self.seo_cat_name_ele, desc="等待列表页seoCatName元素出现")
        return self.driver.current_url

    def verify_home_bridal_jump(self):
        """校验首页bridal的跳转（非导航栏）"""
        self.__wait_content_visible()
        self.click_button(self.home_bridal_ele, desc="点击首页bridal按钮")
        self.wait_element_to_be_visible(self.seo_cat_name_ele, desc="等待列表页seoCatName元素出现")
        return self.driver.current_url

    def verify_home_moms_celebrations_jump(self):
        """校验首页moms_celebrations的跳转（非导航栏）"""
        self.__wait_content_visible()
        self.click_button(self.home_moms_celebrations_ele, desc="点击首页moms_celebrations按钮")
        self.wait_element_to_be_visible(self.seo_cat_name_ele, desc="等待列表页seoCatName元素出现")
        return self.driver.current_url

    def verify_home_party_dresses_jump(self):
        """校验首页party_dresses的跳转（非导航栏）"""
        self.__wait_content_visible()
        self.click_button(self.home_party_dresses_ele, desc="点击首页party_dresses按钮")
        self.wait_element_to_be_visible(self.seo_cat_name_ele, desc="等待列表页seoCatName元素出现")
        return self.driver.current_url

    def verify_home_junior_bridesmaids_jump(self):
        """校验首页junior_bridesmaids的跳转（非导航栏）"""
        self.__wait_content_visible()
        self.click_button(self.home_junior_bridesmaids_ele, desc="点击首页junior_bridesmaids按钮")
        self.wait_element_to_be_visible(self.seo_cat_name_ele, desc="等待列表页seoCatName元素出现")
        return self.driver.current_url

    def verify_home_veils_accessories_jump(self):
        """校验首页veils_accessories的跳转（非导航栏）"""
        self.__wait_content_visible()
        self.click_button(self.home_veils_accessories_ele, desc="点击首页veils_accessories按钮")
        self.wait_element_to_be_visible(self.seo_cat_name_ele, desc="等待列表页seoCatName元素出现")
        return self.driver.current_url

    def verify_home_groomsmen_jump(self):
        """校验首页groomsmen的跳转（非导航栏）"""
        self.__wait_content_visible()
        self.click_button(self.home_groomsmen_ele, desc="点击首页groomsmen按钮")
        self.wait_element_to_be_visible(self.seo_cat_name_ele, desc="等待列表页seoCatName元素出现")
        return self.driver.current_url

    def verify_home_at_home_try_on_dresses_jump(self):
        """校验首页at_home_try_on_dresses的跳转（非导航栏）"""
        self.__wait_content_visible()
        self.remove_launcher()
        self.click_button(self.home_at_home_try_on_dresses_ele, desc="点击首页at_home_try_on_dresses按钮并切换窗口")
        self.wait_element_to_be_visible(self.how_it_works_banner_ele, desc="等待列表页title元素出现")
        return self.driver.current_url

    def verify_instagram_view_all_jump(self):
        """校验首页Instagram的View All按钮的跳转"""
        self.__wait_content_visible()
        self.click_button(self.view_all_btn_ele, desc="点击首页Instagram的View All按钮")
        self.wait_element_to_be_visible(self.style_gallery_page_ele, desc="等待galleryBanner元素出现")
        return self.driver.current_url

    def verify_click_one_instagram_item(self):
        """点击Instagram的第一张图片"""
        self.__wait_content_visible()
        self.click_button(self.first_instagram_item_ele, desc="点击Instagram的第一张图片")
        return True if self.wait_element_visible_and_return_status(self.fs_detail_container_ele) else False
